<template>
	<view class="agent-store-datas" :style="{background:pageColor}" v-if="isLoad">
		<view v-for="(item,index) in list.data" :key="index">
			<longbingbing-shopstore-list-item from="store-datas" :info="item"></longbingbing-shopstore-list-item>
		</view>

		<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading" v-if="loading">
		</load-more>

		<abnor :isCenter="true" :tip="[{text: '暂无门店数据'}]" v-if="!loading&&list.data.length<=0&&list.current_page==1">
		</abnor>

		<view class="space-footer"></view>

		<w-picker mode="range" :startYear="startYear*1-10" :endYear="startYear" :value="toDay" :current="false"
			fields="day" @confirm="onConfirm($event)" :disabled-after="false" ref="day" :themeColor="primaryColor"
			:visible.sync="showDate">
		</w-picker>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from "vuex"
	import longbingbingShopstoreListItem from "@/components/longbingbing-shopstore-list-item.vue"
	export default {
		components: {
			longbingbingShopstoreListItem
		},
		data() {
			return {
				isLoad: false,
				showDate: false,
				startYear: '',
				toDay: '',
				param: {
					page: 1,
					title: ''
				},
				list: {
					data: []
				},
				loading: true,
			}
		},
		computed: mapState({}),
		async onLoad(options) {
			this.options = options
			await this.initIndex()
			this.isLoad = true
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh();
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.list.current_page >= this.list.last_page || this.loading) return;
			this.param.page = this.param.page + 1;
			this.loading = true;
			this.getList();
		},
		methods: {
			...mapMutations([]),
			async initIndex(refresh = false) {
				await this.getList()
				this.$util.setNavigationBarColor({
					bg: this.primaryColor
				})
				// #ifdef H5
				if (!refresh) {
					this.$jweixin.hideOptionMenu()
				}
				// #endif
			},
			initRefresh() {
				this.param.page = 1
				this.initIndex(true)
			},
			toSearch(val) {
				this.param.title = val
				this.getList(1)
			},
			async getList(page) {
				if (page) {
					this.param.page = 1
				}
				let {
					list: oldList,
					param
				} = this
				let newList = await this.$api.agent.storeDataList(param)
				if (this.param.page == 1) {
					this.list = newList
				} else {
					newList.data = oldList.data.concat(newList.data)
					this.list = newList
				}
				this.loading = false
				this.$util.hideAll()
			}
		}
	}
</script>


<style lang="scss">
	.agent-store-datas {
		.list-item {
			.cover {
				width: 160rpx;
				height: 143rpx;
			}
		}
	}
</style>